
<?php
ini_set("display_errors", "On");
error_reporting(E_ALL | E_STRICT);

require __DIR__.'/../app/utils/AyoUtils.php';
AyoUtils::init();


/**
 * 任务：
 * 1 客户端提交关键词
 * 2 服务器端获取用户表单提交的关键词
 * -- 1 GET方式，通过$_GET获取  print_r($_GET)
 * -- 2 POST方式，通过$_POST获取
 * -- 3 什么方式，都可以通过$_REQUEST获取
 */

/*
if(isset($_POST["submit"])){
    echo "提交过来了";
} else {
    echo "submit is no come~";
}*/

function addresstolatlag($address){

//    $url='http://api.map.baidu.com/geocoder/v2/?address='.$address.'&output=json&ak=kyB5G3PzR3XoDACrNt6iVb4v5PKIFvqg';
//    $url='http://api.map.baidu.com/geocoder/v2/?address='.$address.'&output=json&ak=kyB5G3PzR3XoDACrNt6iVb4v5PKIFvqg&callback=showLocation';
//    if($result=file_get_contents($url))
//    {
//        echo $result;
//        $res= explode(',"lat":', substr($result, 40,36));
//        return   $res;
//    }

    try{
        $url='http://restapi.amap.com/v3/geocode/geo?key=f9625737c0a3b28c97b54db3a3549513&address=' . $address;//f9625737c0a3b28c97b54db3a3549513
        if($result=file_get_contents($url))
        {
            //{"status":"1","info":"OK","infocode":"10000","count":"1","geocodes":[{"formatted_address":"北京市昌平区回龙观西大街|21号","province":"北京市","citycode":"010","city":"北京市","district":"昌平区","township":[],"neighborhood":{"name":[],"type":[]},"building":{"name":[],"type":[]},"adcode":"110114","street":"回龙观西大街","number":"21号","location":"116.335846,40.079930","level":"门牌号"}]}
            //"location":"116.335846,40.079930"
            $json_array = json_decode($result, true);
            echo $json_array['geocodes'][0]["location"];
            $res= explode(',', $json_array['geocodes'][0]["location"]);
            return $res;
        }
    }catch (Exception $e){
        return null;
    }


}


addresstolatlag("北京市昌平区回龙观西大街21号");

$keyword = isset($_GET['keyword']) ? trim($_GET['keyword']): "";

if(!isset($_GET['keyword'])){
    echo "没有参数<br/>";
}else{
    try{
        $db = PDOManager::getDB();

        //SELECT * FROM `maigade_seller_location` WHERE ( (`store_name` LIKE '%1219%') AND (`street` LIKE '%1219%') AND (`province` LIKE '%1219%') AND (`city` LIKE '%1219%') AND (`county` LIKE '%1219%') AND (`town` LIKE '%1219%') AND (`specific_address` LIKE '%1219%') )
        $sql = "select * from contact where user_id=:user_id and (real_name = :keyword_real_name)";
//        $likeParam = "%" . $keyword . "%";
        $likeParam = $keyword;
        $rows = PDOManager::findAll($db, $sql, array(
                "user_id"=>18,
                "keyword_real_name"=>$likeParam
//                "keyword_id"=>18
        ));



//        if(count($rows) == 0){
//            echo "没有匹配";
//        }else{
//            foreach ($rows as $row) {
//                echo $row["real_name"] . "<br/>";
//            }
//        }

        ///释放
        $db = null;

    }catch (PDOException $e){
        echo "<hr/>";
        echo "出错：" + $e->getMessage();
        echo "<hr/>";
        $dbh = null;
    }
}



//
?>

<!doctype html>
<html class="no-js" lang="zh">
<head>
    <meta charset="utf-8">
<html>
    <head>
        <meta charset="utf-8" />
        <title>mysql模糊查询</title>
    </head>

    <body>
        <h1>Mysql模糊查询</h1>
        <form action="" method="GET">

            用户名：<input type="text" name="keyword" value="<?php echo $keyword; ?>" />
            <input type="submit" value="查询" />

        </form>

        <?php
            if($rows){
                echo '<table border="1" cellpadding="5">';

                ///打印表头
                $row = $rows[0];
                echo '<tr>';
                foreach ($row as $name => $value){
                    echo "<th>" . $name . "</th>";
                }
                echo '</tr>';

                ///打印内容
                foreach($rows as $row){
                    echo '<tr>';

                    foreach ($row as $name => $value){
                        echo "<td>" . $value . "</td>";
                    }

                    echo '</tr>';
                }

                echo '</table>';
            }else{
                echo "请输入关键词查询~~";
            }

        ?>

    </body>

</html>